package com.suifeng.mq.order.controller;

import com.suifeng.mq.common.utils.DateUtils;
import com.suifeng.mq.common.utils.R;
import com.suifeng.mq.common.utils.ResponseMessage;
import com.suifeng.mq.order.entity.OrderEntity;
import com.suifeng.mq.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 下单功能
     * @return
     */
    @GetMapping("/createOrder")
    public ResponseMessage createOrder() {

        orderService.createOrder();
        return ResponseMessage.ofSuccess("下单成功！"+" 当前下单时间为:"+ DateUtils.formatDateTime(new Date()));

    }

    @GetMapping("/status/{orderSn}")
    public R getOrderStatus(@PathVariable("orderSn") String orderSn){
        OrderEntity orderEntity = orderService.getOrderStatus(orderSn);
        return R.ok().setData(orderEntity);
    }

}
